﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Universe.OneC.DomainModel
{
    public class MetaGeneralInfo
    {
        public string Name, Synonym, Version;

        public override string ToString()
        {
            string title = 
                string.IsNullOrEmpty(Synonym)
                ? Name 
                : Synonym;

            if (string.IsNullOrEmpty(title))
                title = "Неизвестная конфигурация";

            return
                string.IsNullOrEmpty(Version)
                    ? (title + " (Неизветная версия)")
                    : Version + ". " + title;

        }

        public static MetaGeneralInfo Get(Adapter1C adapter)
        {
            
            object metadata = adapter.GetMetadata();
            string name = (string)metadata.Get("Имя");
            string version = (string)metadata.Get("Версия");
            string synonym = (string)metadata.Get("Synonym");
            metadata.ReleaseComObject();

            return new MetaGeneralInfo()
                       {
                           Name = name,
                           Synonym = synonym,
                           Version = version
                       };


        }
    }
}
